package com.groupseven.backend.services.impl;

import com.groupseven.backend.domain.Menu.MenuItem;
import com.groupseven.backend.mapper.MenuMapper;
import com.groupseven.backend.services.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Transactional
@Service
public class MenuServiceImpl implements MenuService {
    @Autowired
    private MenuMapper menuMapper;

    public List<MenuItem> getMenuItemByRole(int Rolenumber){
        return menuMapper.getMenuItemByRole(Rolenumber);
    }

    public List<MenuItem> getSubMenuItemByRole(int Rolenumber){
        return menuMapper.getSubMenuItemByRole(Rolenumber);
    }

    public int deleteMenuByRole(int Rolenumber){
        return menuMapper.deleteMenuByRole(Rolenumber);
    }

    public int addMenuByRole(int Rolenumber,int menuid){
        return menuMapper.addMenuByRole(Rolenumber,menuid);
    }

    public int updateRoleMenus(int Rolenumber, Map<String,Object> query){
        long begintime = System.currentTimeMillis();
        if (menuMapper.deleteMenuByRole(Rolenumber)>=0){
            long endtime=System.currentTimeMillis();
            long costTime = (endtime - begintime);
            System.out.println("删除耗时："+costTime);
            begintime = System.currentTimeMillis();
            System.out.println(query);
            int x = menuMapper.addMenusByRoleAndPermid(query);
            System.out.println("x的值："+x);
            endtime=System.currentTimeMillis();
            costTime = (endtime - begintime);
            System.out.println("插入耗时："+costTime);
            return x;
        }
        return 0;
    }

    public List<MenuItem> getAllParentMenuItem(){
        return menuMapper.getAllParentMenuItem();
    }

    public List<MenuItem> getAllSubMenuItem(){
        return menuMapper.getAllSubMenuItem();
    }
}
